﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public sealed class ClassBLL : IClassBLL
    {
        private static readonly IClassDAL DAL = DataAccess.CreateClasses();

        private EmployeeTypeInfo emptInfo = new EmployeeTypeInfo();
        private PositionTypeInfo postInfo = new PositionTypeInfo();
        private ClassInfo cInfo = new ClassInfo();
        public DataSet LoadClasses(Nullable<int> Sequence, Nullable<int> PositionType, Nullable<int> EmployeeType)
        {
            cInfo.Sequence = Sequence.HasValue ? (int)Sequence : 0;

            if (PositionType.HasValue)
            {
                postInfo.Sequence = (int)PositionType;
                cInfo.PositionTypes = postInfo;
            }
            if (EmployeeType.HasValue)
            {
                emptInfo.Sequence = (int)EmployeeType;
                cInfo.EmployeeTypes = emptInfo;
            }
            return DAL.LoadClasses(cInfo);
        }
        public DataSet LoadClassList(Nullable<int> Sequence, Nullable<int> EmployeeType, Nullable<int> PosSeq, Nullable<int> FieldSeq, Nullable<int> ClassSpecSeq)
        {
            return DAL.LoadClassList(Sequence, EmployeeType, PosSeq, FieldSeq, ClassSpecSeq);
        }
        public IList<ClassInfo> ListClasses()
        {
            return DAL.ListClasses(new ClassInfo(0));
        }
        public IList<ClassInfo> ListClasses(string PositionTypes)
        {
            postInfo.Sequence = PositionTypes.Length > 0 ? Int32.Parse(PositionTypes) : 0;
            cInfo.PositionTypes = postInfo;

            return DAL.ListClasses(cInfo);
        }
         public IList<ClassInfo> ListClassesBySequence(int Sequence)
        {
            return DAL.ListClasses(new ClassInfo(Sequence));
        }

        public void Insert(string Name, string NameShort, string NameEng, string NameEngShort
          , string PositionTypes, string EmployeeTypes, string Remarks, int Createdby)
         { 
                if (EmployeeTypes.Length > 0)
                    emptInfo.Sequence = Int32.Parse(EmployeeTypes);
                if (PositionTypes.Length > 0)
                    postInfo.Sequence = Int32.Parse(PositionTypes);

            DAL.Insert(new ClassInfo(0, Name, NameShort, NameEng, NameEngShort, Remarks, Createdby, 0
                , postInfo, emptInfo)); 
        }
        public void Update(int Sequence, string Name, string NameShort, string NameEng, string NameEngShort
            , string PositionTypes, string EmployeeTypes, string Remarks, int UpdatedBy)
        {
            try
            {
                if (EmployeeTypes.Length > 0)
                    emptInfo.Sequence = Int32.Parse(EmployeeTypes);
                if (PositionTypes.Length > 0)
                    postInfo.Sequence = Int32.Parse(PositionTypes);

                DAL.Update(new ClassInfo(Sequence, Name, NameShort, NameEng, NameEngShort, Remarks, 0, UpdatedBy
                    , postInfo, emptInfo));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
      
    }
}
